package com.github.tommas.admintpl.security.permission.restriction;

import java.util.ArrayList;
import java.util.Collection;

public abstract class ListDataRestriction<T> extends ArrayList<T> implements AssertableRestriction<T>, Restriction {

    public ListDataRestriction(Collection<T> dataset) {
        super(dataset);
    }

    @Override
    public void assertRestriction(T data) {
        for (T d : this) {
            if (data.equals(d)) {
                return;
            }
        }

        throw new RuntimeException(String.format("Invalid data: %s for restriction: %s", data, getName()));
    }
}
